/**
 * Created by Administrator on 2017/6/12 0012.
 * by郑春阳
 */
/**
 自开发 -> json to form js工具
 生成form最终表单
 name:表单name
 action:表单提交地址
 method:提交方式 get / post
 json:需要生成的表单dom集合
 */

/**
 * 可拓展json结构
 */
var dic_list = '';
var tp_id=[];//用于返回特定页面的照片id
function formStart_sub(data){
    var item_name = data.name; //子集名称
    var change_item = data.change_item;//已经提交审核的子集项
    var temp_id = 0;  //点击字段选中对应input框
    var q=0;//用于添加页面照片id数据
    dic_list = data.dic;
    var form = createForm({action:data.action,name:data.name,method:data.method});
    //追加表格数据
    form.append($('<div class="weui-cells_form"></div>'));
    //检测该子集是否有值
    var default_value = data.value;
    //获取子集结构
    var json = data.json;
    //获取扩展配置信息
    var kz_json = data.kz_json;
    //获取对象长度
    var a = 0;
    for(var i in json){
        a++;
    }
    if(a==0){
        //这里使用weui样式
        alert('没有该子集显示项!');
        history.back(-1);
        return;
    }
    if( (default_value==undefined) || (default_value.length==0) ){
        //无值状态 加载默认数据
        for(var i in json){
            //检测是否是为时间标签
            if(json[i].type=='DATE'){
                var date_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputDate_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                //生成date节点
                var date_obj = $(date_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                date_obj.find('label').eq(0).html(html);
                //生成右侧日期input表单
                var createDateValue = {
                    name:i,
                    value:'',
                    caption:json[i].caption
                };

                var temp_date = createTime(createDateValue,kz_json[i],temp_id);
                date_obj.find('div:eq(1)').append(temp_date);
                form.find('div:eq(0)').append(date_obj);
                temp_id++;
            }else if(json[i].type=='LIST' || json[i].type=='LIST1'){
                //生成select节点
                //<div class="form-group"><div class="col-sm-10"><select class="form-control" id=""><option value=""></option></select></div></div>
                var select_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputList_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                var select_obj = $(select_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                select_obj.find('label').eq(0).html(html);
                //分析字典 默认值
                var dictionaries = json[i].dictionaries;
                var select_data = {
                    name:i,
                    dictionaries:dictionaries,
                    default_value:''
                };
                var select = createSelect(select_data,kz_json[i],temp_id);
                select_obj.find('div:eq(1)').append(select);
                form.find('div:eq(0)').append(select_obj);
                temp_id++;
            }else if(json[i].type == 'LAYER'){
                /**************树形字典**************/
                var layer_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputLayer_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                //生成layer节点
                var layer_obj = $(layer_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                layer_obj.find('label').eq(0).html(html);
                //生成右侧文本input表单
                var createLayerValue = {
                    name:i,
                    dictionaries:json[i].dictionaries,
                    default_value:''
                };
                // console.log(createLayerValue)
                var layer_text = createLayer(createLayerValue,kz_json[i],temp_id);
                layer_obj.find('div:eq(1)').append(layer_text);
                form.find('div:eq(0)').append(layer_obj);
                temp_id++;
            }else if(json[i].type=='NUMBER'){
                var number_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputNumber_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                //生成text节点
                var number_obj = $(number_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                number_obj.find('label').eq(0).html(html);
                //生成右侧文本input表单
                var createNumberValue = {
                    name:i,
                    value:'',
                    caption:json[i].caption
                };
                var temp_number = createNumber(createNumberValue,kz_json[i],temp_id);
                number_obj.find('div:eq(1)').append(temp_number);
                form.find('div:eq(0)').append(number_obj);
                temp_id++;
            }else if(json[i].type == 'FILE'){
                var file_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputFile_'+temp_id+'"></label><div class="col-sm-4"><div class="fj"><div class="file_warp"></div></div></div></div>';
                //生成text节点
                var file_obj = $(file_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                file_obj.find('label').eq(0).html(html);

                //生成右侧文本input表单
                var createFileValue = {
                    name:i,
                    caption:json[i].caption
                };

                var temp_file = createFile(createFileValue,kz_json[i],temp_id);
                file_obj.find('.file_warp').append(temp_file);
                form.find('div:eq(0)').append(file_obj);
                temp_id++;
            }else{
                var text_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputText_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                //生成text节点
                var text_obj = $(text_html);
                //生成左侧标题 必填加上*
                if(kz_json[i]){
                    if(kz_json[i].file){
                        var html = json[i].caption+'<font color="red">*</font>';
                    }else{
                        var html = json[i].caption;
                    }
                }else{
                    var html = json[i].caption;
                }
                text_obj.find('label').eq(0).html(html);
                //生成右侧文本input表单
                var createTextValue = {
                    name:i,
                    value:'',
                    caption:json[i].caption
                };
                var temp_text = createText(createTextValue,kz_json[i],temp_id);
                text_obj.find('div:eq(1)').append(temp_text);
                form.find('div:eq(0)').append(text_obj);
                temp_id++;
            }
        }
        //生成提交按钮 和 返回按钮
        var operation_div = $('<center class="operation_div_3"></center>');
        if(change_item.indexOf(item_name) > -1){
            var submit = $('<input type="button" class="btn btn-info sp" value="此子集已在审批中,不可修改,不可提交审批">');
        }else{
            var submit = $('<input type="submit"  class="btn  btn-default" value="保存">');
            var add = $('<input type="button" class="btn  btn-info add_info" value="新增">');
        }
         operation_div.append(add);
         operation_div.append(submit);
        //添加表单隐藏域信息
        form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
        //标记该子集是否有值 1 有 0 没有
        form.append($('<input type="hidden" name="has_value" value="0"/>'));
        form.find('div:eq(0)').append(operation_div);
        //最终生成dom节点数据
        $('body').append(form);
    }else{
        /***************************有值状态*************************/
        //获取有删除标记的subvalue条数
        var c = 0;
        for(var i in default_value){
            if(default_value[i].no_display){
                c++;
            }
        }
        if(c==default_value.length){
            var type = 1;
            addNew(data,type);
            return;
        }

        //统计总数
        var total = 0;
        var div1 = $('<div class="swiper-container swiper-no-swiping"></div>');
        var div2 = $('<div class="swiper-wrapper swiper-no-swiping"></div>');

        for(var j=0 in default_value){
            if(!default_value[j].no_display) {
                total++;
                var temp = $('<div class="swiper-slide swiper-no-swiping"></div>');
                var form1 = createForm({action: data.action, name: data.name, method: data.method});
                //追加表格数据
                form1.append($('<div class=" weui-cells_form"></div>'));
                var json_info = default_value[j].info;
                var status = 1; //字段是否可编辑
                for (var i in json_info) {
                    //组织数据
                    var date_type    = json_info[i].type; //字段类型
                    var item_caption = json_info[i].caption;  //子段名称
                    var value        = json_info[i].value;  //字段值
                    var change_type  = json_info[i].change_type;  //字段修改状态
                    var wyx          = json_info[i].wyx ;    //是否唯一性
                    //检测是否是为Date类型
                    if (date_type == 'DATE') {
                        var date_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputDate_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                        //生成date节点
                        var date_obj = $(date_html);
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = item_caption+'<font color="red">*</font>';
                            }else{
                                var html = item_caption;
                            }
                        }else{
                            var html = item_caption;
                        }
                        date_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if (change_type == 1) {
                            date_obj.find('label').eq(0).css('color', 'red');
                        }
                        //生成右侧日期input表单
                        var createDateValue = {
                            name: i,
                            value: value,
                            caption: item_caption
                        };
                        var temp_date = createTime(createDateValue,kz_json[i],temp_id,status);
                        date_obj.find('div:eq(1)').append(temp_date);
                        form1.find('div:eq(0)').append(date_obj);
                        temp_id++;
                    } else if (date_type == 'LIST' || date_type == 'LIST1') {
                        //生成select节点
                        // alert(date_type);
                        var select_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputList_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                        var select_obj = $(select_html);
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = item_caption+'<font color="red">*</font>';
                            }else{
                                var html = item_caption;
                            }
                        }else{
                            var html = item_caption;
                        }
                        select_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if (change_type == 1) {
                            select_obj.find('label').eq(0).css('color', 'red');
                        }
                        //分析字典 默认值
                        var select_data = {
                            name: i,
                            dictionaries: json_info[i].dictionaries,
                            default_value: value,
                            wyx : wyx
                        };

                        var select = createSelect(select_data,kz_json[i],temp_id,status);
                        select_obj.find('div:eq(1)').append(select);
                        form1.find('div:eq(0)').append(select_obj);
                        temp_id++;
                    }else if(date_type == 'LAYER'){
                        /**************树形字典**************/
                        var layer_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputLayer_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                        //生成layer节点
                        var layer_obj = $(layer_html);
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = item_caption+'<font color="red">*</font>';
                            }else{
                                var html = item_caption;
                            }
                        }else{
                            var html = item_caption;
                        }
                        layer_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if(change_type == 1){
                            layer_obj.find('label').eq(0).css('color','red');
                        }
                        //生成右侧文本input表单
                        var createLayerValue = {
                            name: i,
                            dictionaries: json[i].dictionaries,
                            default_value: value
                        };
                        // console.log(createLayerValue)

                        var layer_text = createLayer(createLayerValue,kz_json[i],temp_id,status);
                        layer_obj.find('div:eq(1)').append(layer_text);
                        form1.find('div:eq(0)').append(layer_obj);
                        temp_id++;
                    }else if (date_type == 'NUMBER') {
                        var number_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputNumber_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                        //生成text节点
                        var number_obj = $(text_html);
                        //生成左侧标题 必填加上*
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = item_caption+'<font color="red">*</font>';
                            }else{
                                var html = item_caption;
                            }
                        }else{
                            var html = item_caption;
                        }
                        number_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if (change_type == 1) {
                            number_obj.find('label').eq(0).css('color', 'red');
                        }
                        //生成右侧文本input表单
                        var createNumberValue = {
                            name: i,
                            value: value,
                            caption: item_caption
                        };
                        var temp_number = createNumber(createNumberValue,kz_json[i],temp_id,status);
                        number_obj.find('div:eq(1)').append(temp_number);
                        form1.find('div:eq(0)').append(number_obj);
                        temp_id++;
                    }else if(date_type == 'FILE'){
                        var file_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputFile_'+temp_id+'"></label><div class="col-sm-4"><div class="fj"><div class="file_result">';
                        for(var h in value){
                            if(value[h].status != 4){
                                file_html += '<div class="file_info"><span>'+h+'</span><span><a href="'+value[h].href+'">下载</a></span><span><a class="removefile" href="javascript:;" zd_name="'+i+'" offset="'+j+'" filename="'+h+'" onclick="remove_result(this)">删除</a></span></div>'
                            }
                        }
                        file_html += '</div><div class="file_warp"></div></div></div></div>';

                        //生成text节点
                        var file_obj = $(file_html);
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = json[i].caption+'<font color="red">*</font>';
                            }else{
                                var html = json[i].caption;
                            }
                        }else{
                            var html = json[i].caption;
                        }
                        file_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if(change_type == 1){
                            file_obj.find('label').eq(0).css('color','red');
                        }
                        //生成右侧文本input表单
                        var createFileValue = {
                            name:i,
                            caption:item_caption
                        };

                        var temp_file = createFile(createFileValue,kz_json[i],temp_id,status);
                        file_obj.find('.file_warp').append(temp_file);
                        form1.find('div:eq(0)').append(file_obj);
                        temp_id++;
                    }else{
                        var text_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputText_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
                        //生成text节点
                        var text_obj = $(text_html);
                        //生成左侧标题 必填加上*
                        if(kz_json[i]){
                            if(kz_json[i].file){
                                var html = item_caption+'<font color="red">*</font>';
                            }else{
                                var html = item_caption;
                            }
                        }else{
                            var html = item_caption;
                        }
                        text_obj.find('label').eq(0).html(html);
                        //如果有修改,标题置为red
                        if (change_type == 1) {
                            text_obj.find('label').eq(0).css('color', 'red');
                        }
                        //生成右侧文本input表单
                        var createTextValue = {
                            name: i,
                            value: value,
                            caption: item_caption
                        };
                        var temp_text = createText(createTextValue,kz_json[i],temp_id,status);
                        text_obj.find('div:eq(1)').append(temp_text);
                        form1.find('div:eq(0)').append(text_obj);
                        temp_id++;
                    }
                }
                if (change_item.indexOf(item_name) > -1) {
                    var operation_div = $('<center class="operation_div"></center>');
                    var submit = $('<input type="button" class="btn  btn-info sp" value="此子集已在审批中,不可修改,不可提交审批">');
                    operation_div.append(submit);
                } else {
                    //生成提交按钮 和 返回按钮
                    var operation_div = $('<center class="operation_div_2"></center>');
                    var submit = $('<input type="submit"  class="btn  btn-default" value="保存">');
                    var add = $('<input type="button" class="btn  btn-info add_info" value="新增">');
                    var del = $('<input _offset_id='+j+' type="button" class=" btn  btn-danger sub_del" value="删除">');
                    operation_div.append(add);
                    operation_div.append(submit);
                    //operation_div.append(callback);
                    operation_div.append(del);
                }
                //添加表单隐藏域信息
                form1.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
                form1.append($('<input type="hidden" name="has_value" value="1"/>'));
                //追加当前记录位置id
                form1.append($('<input type="hidden" name="_offset_id" value="'+j+'"/>'));
                form1.find('div:eq(0)').append(operation_div);
                //判断审批结果,审批没通过添加审批状态和不通过的原因
                //郑春阳
                var sp_div = $('<div class="reason_area"></div>');
                if (change_item.indexOf(item_name) < 0) {
                    if(default_value[j].sp_type == 1 ){
                        var sp_type_html = $('<div class="weui-msg-check_area"><i class="weui-icon-success weui-check_ok"></i>恭喜！该子集的此条记录审核通过</div>');
                        var reason_html= $('<div class="success_reason"></div>');
                    }else if(default_value[j].sp_type == 0){
                        var sp_type_html = $('<div class="weui-msg-check_area"><i class="weui-icon-warn weui-check_error"></i>抱歉!该子集的此条记录审核未通过</div>');
                        var reason_html = $('<div class="error_reason">不通过意见 : '+default_value[j].reason+'</div>');
                    }else{
                        var sp_type_html = $('<div class="weui-msg-check_area" style="display:none"><i class="weui-icon-success weui-check_ok"></i>站位</div>');
                        var reason_html= $('<div class="success_reason"></div>');
                    }
                    sp_div.append(sp_type_html).append(reason_html);
                    form1.append(sp_div);
                }
                //最终生成dom节点数据
                temp.append(form1);
                div2.append(temp);
            }
        }

        var page = $('<div style="position:fixed;top:-3px;z-index:0;" class="swiper-pagination"></div>');
        //判断单条数据情况 如果单条则隐藏蓝点
        if(total > 1){
            div1.append(page);
        }
        div1.append(div2);
        $('body').append(div1);
    }
}

/**
 * 非可拓展json结构 员工基本信息
 */
function formStart(data){
    var item_name = data.name; //子集名称
    var change_item = data.change_item;//已经提交审核的子集项
    var kz_json = data.kz_json;  //扩展配置数据
    dic_list = data.dic;
    var form = createForm({action:data.action,name:data.name,method:data.method});
    var temp_id = 0;//用于拼接id
    var q=0;//用于添加页面照片id数据
    //追加表格数据
    form.append($('<div class="weui-cells_form"></div>'));
    //获取子集数据
    var json = data.json;
    //获取对象长度
    var a = 0;
    for(var i in json){
        a++;
    }
    if(a==0){
        //这里使用weui样式
        alert('没有该子集显示项!');
        history.back(-1);
        return;
    }
    for(i in json){
        var change_type = json[i].change_type;
        //检测是否是为时间标签
        if(json[i].type=='DATE'){
            var date_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputDate_'+temp_id+'"></label><div class=" col-sm-4"><div class=""></div></div></div>';
            //生成date节点
            var date_obj = $(date_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            date_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                date_obj.find('label').eq(0).css('color','red');
            }
            //生成右侧日期input表单
            var createDateValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_date = createTime(createDateValue,kz_json[i],temp_id,status);
            date_obj.find('div:eq(1)').append(temp_date);
            form.find('div:eq(0)').append(date_obj);
            temp_id++;
        }else if(json[i].type=='LIST' || json[i].type=='LIST1'){
            /**************普通字典**************/
            //生成select节点
            var select_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputList_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            var select_obj = $(select_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            select_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                select_obj.find('label').eq(0).css('color','red');
            }
            //分析字典 默认值
            var select_data = {
                name:i,
                dictionaries:json[i].dictionaries,
                default_value:json[i].value,
                wyx : json[i].wyx
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var select = createSelect(select_data,kz_json[i],temp_id,status);
            select_obj.find('div:eq(1)').append(select);
            form.find('div:eq(0)').append(select_obj);
            temp_id++;
        }else if(json[i].type == 'LAYER'){
            /**************树形字典**************/
            var layer_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputLayer_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成layer节点
            var layer_obj = $(layer_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            layer_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                layer_obj.find('label').eq(0).css('color','red');
            }
            //生成右侧文本input表单
            var createLayerValue = {
                name:i,
                dictionaries:json[i].dictionaries,
                default_value:json[i].value,
                wyx : json[i].wyx
            };
            // console.log(createLayerValue)
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var layer_text = createLayer(createLayerValue,kz_json[i],temp_id,status);
            layer_obj.find('div:eq(1)').append(layer_text);
            form.find('div:eq(0)').append(layer_obj);
            temp_id++;
        }else if(json[i].type=='NUMBER'){
            var number_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputNumber_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成text节点
            var number_obj = $(number_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            number_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                number_obj.find('label').eq(0).css('color','red');
            }
            //生成右侧文本input表单
            var createNumberValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_number = createNumber(createNumberValue,kz_json[i],temp_id,status);
            number_obj.find('div:eq(1)').append(temp_number);
            form.find('div:eq(0)').append(number_obj);
            temp_id++;
        }else if(json[i].type == 'FILE'){
            if(i=='ZP'){
                var file_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputFile_'+temp_id+'" style="position: absolute;left: -99999px;top: -9999px;z-index: 9999;"></label><div class="col-sm-4" ><div class="zp_up"></div></div></div>';
                tp_id[q]='inputFile_'+temp_id;
                q++;
            }else{
                var file_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputFile_'+temp_id+'"></label><div class="col-sm-4"><div class="fj"><div class="file_result">';
                for(var h in json[i].value){
                    if(json[i].value[h].status != 4){
                        file_html += '<div class="file_info"><span>'+h+'</span><span><a href="'+json[i].value[h].href+'">下载</a></span><span><a class="removefile" href="javascript:;" zd_name="'+i+'" filename="'+h+'" offset="0" onclick="remove_result(this)">删除</a></span></div>'
                    }
                }
                file_html += '</div><div class="file_warp"></div></div></div></div>';
            }

            //生成text节点
            var file_obj = $(file_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            file_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                file_obj.find('label').eq(0).css('color','red');
            }
            //生成右侧文本input表单
            var createFileValue = {
                name:i,
                caption:json[i].caption
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_file = createFile(createFileValue,kz_json[i],temp_id,status);
            if(i=='ZP'){
                //隐藏上传照片按钮
                file_obj.find('.zp_up').append(temp_file);
            }else{
                file_obj.find('.file_warp').append(temp_file);
            }

            form.find('div:eq(0)').append(file_obj);
            temp_id++;
        }else{
            var text_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputText_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成text节点
            var text_obj = $(text_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            text_obj.find('label').eq(0).html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                text_obj.find('label').eq(0).css('color','red');
            }
            //生成右侧文本input表单
            var createTextValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_text = createText(createTextValue,kz_json[i],temp_id,status);
            text_obj.find('div:eq(1)').append(temp_text);
            form.find('div:eq(0)').append(text_obj);
            temp_id++;
        }
    }
    //生成提交按钮 和 返回按钮
    var operation_div = $('<center class="operation_div_3"></center>');
    if(change_item.indexOf(item_name) > -1){
        var submit = $('<input type="botton" class="btn btn-info sp" style="width:300px" value="员工基本信息已在审批中,不可修改,不可提交审批">');
    }else{
        var submit = $('<input type="submit"  class="btn  btn-default btn-block" style="width:75%" value="保存">');
    }

    //var callback = $('<input type="button" class="weui-btn weui-btn_disabled weui-btn_default callback_button" value="取消操作">');
    operation_div.append(submit);

    //operation_div.append(callback);
    //添加表单隐藏域信息
    form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
    form.find('div:eq(0)').append(operation_div);
    //判断审批结果,审批没通过添加审批状态和不通过的原因
    //郑春阳
    var sp_div = $('<div class="reason_area"></div>');
    if (change_item.indexOf(item_name) < 0) {
        if(data.sp_type == 1 ){
            var sp_type_html = $('<div class="weui-msg-check_area"><i class="weui-icon-success weui-check_ok"></i>恭喜！员工基本信息修改数据审核通过</div>');
            var reason_html= $('<div class="success_reason"></div>');
        }else if(data.sp_type == 0){
            var sp_type_html = $('<div class="weui-msg-check_area"><i class="weui-icon-warn weui-check_error"></i>抱歉!员工基本信息部分修改数据审核未通过</div>');
            var reason_html = $('<div class="error_reason">不通过意见 : '+data.reason+'</div>');
        }else{
            var sp_type_html = $('<div class="weui-msg-check_area" style="display:none"><i class="weui-icon-success weui-check_ok"></i>站位</div>');
            var reason_html= $('<div class="success_reason"></div>');
        }
        sp_div.append(sp_type_html).append(reason_html);
        form.append(sp_div);
    }
    //最终生成dom节点数据
    $('body').append(form);
}

/**
 * 添加新记录数据
 */
function addNew(data,type){
    dic_list = data.dic;
    var kz_json = data.kz_json;  //扩展配置数据
    var temp_id = 0;
    var q=0;//用于添加页面照片id数据
    if(type == 1){
        var action = '/Pc/Info/addok';
    }else{
        var action = data.action;
    }
    var form = createForm({action:action,name:data.name,method:data.method});
    //追加表格数据
    form.append($('<div class="weui-cells_form"></div>'));
    var json = data.json;
    //获取对象长度
    var a = 0;
    for(var i in json){
        a++;
    }
    //检测是否有数据
    if(a == 0){
        alert('没有该子集显示项!');
        history.back(-1);
        return;
    }
    for(var i in json){
        //检测是否是为Date类型
        if(json[i].type=='DATE'){
            var date_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputDate_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成date节点
            var date_obj = $(date_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            date_obj.find('label').eq(0).html(html);
            //生成右侧日期input表单
            var createDateValue = {
                name:i,
                value:'',
                caption:json[i].caption
            };

            var temp_date = createTime(createDateValue,kz_json[i],temp_id);
            date_obj.find('div:eq(1)').append(temp_date);
            form.find('div:eq(0)').append(date_obj);
            temp_id++;
        }else if(json[i].type=='LIST' || json[i].type=='LIST1'){
            //生成select节点
            var select_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputList_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            var select_obj = $(select_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            select_obj.find('label').eq(0).html(html);
            //分析字典 默认值
            var dictionaries = json[i].dictionaries;
            var select_data = {
                name:i,
                dictionaries:dictionaries,
                default_value:'',
                wyx : json[i].wyx
            };
            var select = createSelect(select_data,kz_json[i],temp_id);
            select_obj.find('div:eq(1)').append(select);
            form.find('div:eq(0)').append(select_obj);
            temp_id++;
        }else if(json[i].type == 'LAYER'){
            /**************树形字典**************/
            var layer_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputLayer_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成layer节点
            var layer_obj = $(layer_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            layer_obj.find('label').eq(0).html(html);

            //生成右侧文本input表单
            var createLayerValue = {
                name:i,
                default_value:'',
                dictionaries:json[i].dictionaries
            };
            // console.log(createLayerValue)
            var layer_text = createLayer(createLayerValue,kz_json[i],temp_id);
            layer_obj.find('div:eq(1)').append(layer_text);

            form.find('div:eq(0)').append(layer_obj);
            temp_id++;
        }else if(json[i].type=='NUMBER'){
            var number_html = '<div class=" form-group "><label class="col-sm-2  control-label" for="inputNumber_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成text节点
            var number_obj = $(number_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            number_obj.find('label').eq(0).html(html);
            //生成右侧文本input表单
            var createNumberValue = {
                name:i,
                value:'',
                caption:json[i].caption
            };
            var temp_number = createNumber(createNumberValue,kz_json[i],temp_id);
            number_obj.find('div:eq(1)').append(temp_number);
            form.find('div:eq(0)').append(number_obj);
            temp_id++;
        }else if(json[i].type == 'FILE'){
            var file_html = '<div class="form-group"><label class="col-sm-2  control-label" for="inputFile_'+temp_id+'"></label><div class="col-sm-4"><div class="fj"><div class="file_warp"></div></div></div></div>';
            //生成text节点
            var file_obj = $(file_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            file_obj.find('label').eq(0).html(html);
            //生成右侧文本input表单
            var createFileValue = {
                name:i,
                caption:json[i].caption
            };
            var temp_file = createFile(createFileValue,kz_json[i],temp_id);
            file_obj.find('.file_warp').append(temp_file);
            form.find('div:eq(0)').append(file_obj);
            temp_id++;
        }else {
            var text_html = '<div class="form-group "><label class="col-sm-2  control-label" for="inputText_'+temp_id+'"></label><div class="col-sm-4"><div class=""></div></div></div>';
            //生成text节点
            var text_obj = $(text_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            text_obj.find('label').eq(0).html(html);
            //生成右侧文本input表单
            var createTextValue = {
                name:i,
                value:'',
                caption:json[i].caption
            };
            var temp_text = createText(createTextValue,kz_json[i],temp_id);
            text_obj.find('div:eq(1)').append(temp_text);
            form.find('div:eq(0)').append(text_obj);
            temp_id++;
        }
    }
    var operation_div = $('<center class="operation_div"></center>');
    var submit = $('<input type="submit" class="btn btn-default btn-block" value="提交保存">');
    operation_div.append(submit);
    //添加表单隐藏域信息
    form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
    form.find('div:eq(0)').append(operation_div);
    //最终生成dom节点数据
    $('body').append(form);
}

/**
 * 生成form表单对象
 */
function createForm(args){
    var dom = $("<form name='"+args.name+"' action='"+args.action+"' method='"+args.method+"' enctype='multipart/form-data'></form>");
    var file_html = $('<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />');
    dom.append(file_html);
    return dom;
}

/**
 * 生成text文本表单对象
 */
function createText(data,kz_info,temp_id,status){
    var val = data.value;
    var text_input = $('<input class="form-control"  type="text" id="inputText_'+temp_id+'" placeholder="请输入'+data.caption+'"/>');
    if(kz_info){
        if(kz_info.file){
            text_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            text_input.attr({
                disabled:'disabled'
            });
        }
    }
    text_input.attr({
        name:data.name,
        value:val
    });

    return text_input;
}
/**
 * 生成file 文件对象
 */
function createFile(data,kz_info,temp_id,status){
    if(data.name =='ZP'){
        var file_input = $('<input class="form-control" name="ZP[]" type="file" id="inputFile_'+temp_id+'" onchange="fileZpSize(this);"/>');
    }else{
        var file_input = $('<span><span class="file_add"><a class="clonebtn" href="javascript:;"onclick="add_file(this);" >[+]</a></span></span><input class="form-control file_input" multiple  type="file" name="'+data.name+'[]" id="inputFile_'+temp_id+'" onchange="fileFJSize(this);"/>');
        // var file_input = $('<span class="file_add"><span ><a href="javascript:;">[+]</a></span></span><input class="form-control file_input" multiple  type="file" name="'+data.name+'[]" id="inputFile_'+temp_id+'"/><span class="file_result"><span>1.pdf</span><span><a href="javascript:;">删除</a></span></span>');
    }
    if(kz_info){
        if(kz_info.file){
            file_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            file_input.attr({
                disabled:'disabled'
            });
        }
    }

    return file_input;
}
/**
 * 生成数字表单对象
 */
function createNumber(data,kz_info,temp_id,status){
    var val = data.value;
    var number_input = $('<input class="form-control"  type="number" id="inputNumber_'+temp_id+'"  placeholder="请输入'+data.caption+'"/>');
    if(kz_info){
        if(kz_info.file){
            number_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            number_input.attr({
                disabled:'disabled'
            });
        }
    }
    number_input.attr({
        name:data.name,
        value:val
    });
    return number_input;
}

/**
 * 生成时间对象
 */
function createTime(data,kz_info,temp_id,status){
    if(typeof data.value =='undefined'){
        var time=data.value;
    }else{
        //截取时间长度Y-M-D
        var time=data.value.substr(0,10);
    }
    var time_input = $('<input  class="form-control date" zjm="'+data.name+'" type="text" id="inputDate_'+temp_id+'" readonly="readonly"/>');
    if(kz_info){
        if(kz_info.file){
            time_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            time_input.attr({
                disabled:'disabled'
            });
        }
    }

    time_input.attr({
        name:data.name,
        value:time
    });
    return time_input;
}

/**
 * 生成普通下拉select对象
 */
function createSelect(data,kz_info,temp_id,status){
    if(data.wyx){
        var select_input = $('<select class="form-control checkWyx"  id="inputList_'+temp_id+'" ></select>');
    }else{
        var select_input = $('<select class="form-control"  id="inputList_'+temp_id+'" ></select>');
    }

    if(kz_info){
        if(kz_info.file){
            select_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            select_input.attr({
                disabled:'disabled'
            });
        }
    }
    select_input.attr({
        name:data.name,
        dictionaries:data.dictionaries
    });

    var dictionaries = data.dictionaries;
    var select_input = getDictionaries(dictionaries,data.default_value,select_input);
    return select_input;
}


/**
 * 获取普通字典下拉
 */
function getDictionaries(id,default_value,select_obj){
    var fir_option = $('<option value="">请选择</option>');
    //判断默认值否是为空
    //添加默认项节点
    select_obj.append(fir_option);

    var obj = dic_list[id];

    if(!obj){
        return select_obj;
    }
    var dic_subitem = obj.subitem;
    var tob = 0;
    for(var j=0;j<dic_subitem.length;j++){
        var option = $('<option></option>');
        //判断是否显示
        if(dic_subitem[j].display==true){
            option.attr({
                value:dic_subitem[j].caption
            });
            //默认值选中
            if(dic_subitem[j].caption==default_value){
                tob = 1;
                option.attr({
                    selected:true
                });
            }
            option.html(dic_subitem[j].caption);
            select_obj.append(option);
        }
    }
    if(tob==0 && default_value){
        select_obj.append($('<option style="display:none" value="'+default_value+'" selected>'+default_value+'</option>'));
    }
    return select_obj;
}


/**
 * 生成layer文本表单对象
 */
var layer_id = [];
function createLayer(data,kz_info,temp_id,status){
    var id = data.dictionaries;
    var item = layer_js[id];
    //console.log(item);
    var val = data.default_value;

    //取到id和对应的数据字典名称
    if(id == 'BO_CASC_HR_JCXX_JG'){
        var layer_input = $('<input class="form-control ztree"  type="text"  id="inputLayer_'+temp_id+'" placeholder="请选择" />');
    }else{
        var layer_input = $('<input class="form-control ztree"  type="text"  id="inputLayer_'+temp_id+'" placeholder="请选择" readonly="readonly"/>');
    }

    var temp_layer = 'inputLayer_'+temp_id;
    var temp_layer_id = id;
    layer_id[temp_layer] = temp_layer_id;
    // console.log(layer_id);
    if(kz_info){
        if(kz_info.file){
            layer_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            layer_input.attr({
                disabled:'disabled'
            });
        }
    }
    // console.log(layer_js);
    layer_input.attr({
        name:data.name,
        value:val
    });
    return layer_input;
}
